import 'package:my_flutter_github/model/UserEvent.dart';
import 'package:redux/redux.dart';

/// 事件Redux
final UserEventReducer = combineReducers<List<UserEvent>>([
  TypedReducer<List<UserEvent>, RefreshEventAction>(_refresh),
  TypedReducer<List<UserEvent>, LoadMoreEventAction>(_loadMore),
]);

List<UserEvent> _refresh(List<UserEvent> list, action) {
  list.clear();
  if (action.list == null) {
    return list;
  } else {
    list.addAll(action.list);
    return list;
  }
}

List<UserEvent> _loadMore(List<UserEvent> list, action) {
  if (action.list != null) {
    list.addAll(action.list);
  }
  return list;
}

class RefreshEventAction {
  final List<UserEvent> list;

  RefreshEventAction(this.list);
}

class LoadMoreEventAction {
  final List<UserEvent> list;

  LoadMoreEventAction(this.list);
}
